home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Shareware Plus / Developers / DLOGManager 1.02 / Source Code / StandAlone.cp < prev    next >
Encoding:
Text File  |  1996-09-16  |  4.3 KB  |  203 lines  |  [TEXT/KAHL]

  1. /*** File: "StandAlone_v00.c"
  2. *
  3. *    Versione 00. Del 25-09-94.
  4. *    Scritto da Cadili Francesco.
  5. *
  6. *    Legge i dati relativi ad un film da DB.
  7. ************************************************/
  8. #include "StandAlone_v00.h"
  9. #include <Windows.h>
  10. #include <Dialogs.h>
  11. #include <Fonts.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Resources.h>
  15. #include <Memory.h>
  16. #include <Menus.h>
  17. #include <Desk.h>
  18.  
  19. /******** Dichiarazioni private ************************/
  20. /******** Include Locali *******************************/
  21.  
  22. #include "StandAloneMenu_v00.h"
  23. #include "stringUtility_v02.h"
  24. #ifdef CONTROLLORISORSE
  25. #include "ControlloRisorse.h"
  26. #endif
  27. #pragma segment StandAlone
  28. /******** Fine Include Locali **************************/
  29. /******** Strutture dati locali ************************/
  30.  
  31. /********* Fine Strutture dati locali *******************/
  32. /******** Costanti locali ******************************/
  33.  
  34. #define ckkID 128
  35. WindowPtr frontmost;
  36. Cursor iBeam;
  37.  
  38. /******** Fine Costanti locali *************************/
  39. /******** Funzioni private: ****************************/
  40.  
  41. void InitMacintosh(void);
  42. int HandleMouseDown(EventRecord *theEvent);
  43. int HandleEvent(void);
  44. int checkForCode(void);
  45. void CantOpen(void);
  46.  
  47. /******** Fine Funzioni private ************************/
  48. /******** Fine Dichiarazioni private ********************/
  49.  
  50. /*** InitMacintosh()
  51. *
  52. *    Inizializza i manager e la memoria
  53. ****************************************/
  54. void InitMacintosh(void)
  55. {
  56.     MaxApplZone();
  57.     InitGraf(&qd.thePort);
  58.     InitFonts();
  59.     FlushEvents(everyEvent, 0);
  60.     InitWindows();
  61.     InitMenus();
  62.     TEInit();
  63.     InitDialogs(0L);
  64.     InitCursor();
  65. }
  66. /* end InitMacintosh */
  67.  
  68.  
  69. /*** HandleMouseDown(&theEvent)
  70. *
  71. *    Elabora un evento di tipo "mouse Down".
  72. *
  73. *    Par INPUT:    'theEvent' il descrittore dell'evento corrente.
  74. *    Val OUTPUT:    TRUE se deve proseguire nell'elaborazione
  75. *                FALSE se deve terminare.
  76. *
  77. *****************************************************************/
  78. int HandleMouseDown (EventRecord *theEvent)
  79. {
  80.     WindowPtr    theWindow;
  81.     int            windowCode = FindWindow(theEvent->where, &theWindow);
  82.     int            computeNext = true;
  83.  
  84.     switch (windowCode)
  85.     {
  86.         case inSysWindow: 
  87.             SystemClick (theEvent, theWindow);
  88.             break;
  89.         
  90.         case inMenuBar:
  91.             computeNext = HandleMenu(MenuSelect(theEvent->where));
  92.             break;
  93.     }
  94.     return(computeNext);
  95. }
  96. /* end HandleMouseDown */
  97.  
  98.  
  99. /*** HandleEvent()
  100. *
  101. *    Elabora un evento. (elabora solo un evento).
  102. *
  103. *    Val OUTPUT:    TRUE se deve proseguire nell'elaborazione
  104. *                FALSE se deve terminare.
  105. *
  106. ************************************************************/
  107. int HandleEvent(void)
  108. {
  109.     int            evento;
  110.     int            computeNext = true;
  111.     EventRecord    theEvent;
  112.  
  113.     HiliteMenu(0);
  114.     SystemTask ();            // permette l'elaborazione ai "desk accessory"
  115.  
  116.     evento = GetNextEvent (everyEvent, &theEvent);
  117.     if (evento)
  118.         switch (theEvent.what)
  119.         {
  120.             case mouseDown:
  121.                 computeNext = HandleMouseDown(&theEvent);
  122.                 break;
  123.  
  124.             case keyDown:
  125.             case autoKey:
  126.                 if ((theEvent.modifiers & cmdKey) != 0)
  127.                       computeNext = HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  128.                 break;
  129.         }
  130.     return(computeNext);
  131. }
  132. /* end HandleEvent */
  133.  
  134. /*** main()
  135. *
  136. ********************/
  137. void main(void)
  138. {
  139.     CursHandle    hCurs;
  140.  
  141.     InitMacintosh();
  142.     if (!checkForCode())
  143.     {
  144.         SysBeep(20);
  145.         CantOpen();
  146.         return;
  147.     }
  148.     SetUpMenus();
  149.  
  150.     hCurs = GetCursor(1);
  151. #ifdef CONTROLLORISORSE
  152.     CaricaRisorsa('CURS', 1);
  153. #endif
  154.     if (hCurs == NULL)
  155.         iBeam = qd.arrow;
  156.     else
  157.         iBeam = **hCurs;
  158.  
  159.     while(HandleEvent());
  160. }
  161. /* end main */
  162.  
  163. /*** checkForCode()
  164. *
  165. *    Controlla la presenza del codice di controllo.
  166. *
  167. *    Val OUTPUT: TRUE se รจ presente, FALSE altrimenti.
  168. *
  169. *****************************************************/
  170. int checkForCode(void)
  171. {
  172.     Handle chkHdl;
  173.  
  174. #ifdef CONTROLLORISORSE
  175.     CaricaRisorsa('chk?', ckkID);
  176. #endif
  177.     return(compareCHandleToPascal(GetResource('chk?', ckkID), "\pcode:10200"));
  178. }
  179. /* end checkForCode */
  180.  
  181. /*** CantOpen()
  182. *
  183. *    Errore nell'apertura del file delle risorse
  184. *
  185. *****************************************************/
  186. void CantOpen(void)
  187. {
  188.     Rect r;
  189.     WindowPtr window;
  190.  
  191.     SetRect(&r, 152, 60, 410, 132);
  192.     SetPort((window = NewWindow( (Ptr) 0L, &r, "\p", true, dBoxProc, (WindowPtr) -1L, false, 0L)));
  193.     TextFont(0);
  194.     MoveTo(4, 20);
  195.     DrawString("\pNon posso aprire il file delle risorse.");
  196.     MoveTo(4, 40);
  197.     DrawString("\pPremi il bottone del mouse per uscire.");
  198.     do {
  199.     } while (!Button());
  200. }
  201. /* end CantOpen */
  202.